package org.surthi.app.bank.db.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.surthi.app.bank.db.dvo.Account;

public class AccountDaoImpl extends HibernateDaoSupport implements AccountDao {

	public List getAllAccounts(){
		List results = null;
//		getHibernateTemplate().("select account from Account account");
		try {
		System.out.println("In get All Accounts Method.");
	
		Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Account.class);
		results = criteria.list();
		if (results.isEmpty()){
			System.out.println("Found response Empty List");
		}
		}catch(Exception exp){
			System.out.println("Error: "+ exp.getMessage());
		}
		return results;
	}
	public List<String> getAllAccountNumbers(){
		List<String> results = getHibernateTemplate().find("select account.accountId from Account account");
		return results;
	}
	public Account findAccount(String accountId) {
		Account account = null;
		account = (Account) getHibernateTemplate().get(Account.class, accountId);
		return account;
	}
	public void saveAccount(Account account) {
		getHibernateTemplate().save(account);
	}
	public void updateAccount(Account account) {
		getHibernateTemplate().saveOrUpdate(account);		
	}
}
